// DlgChildBase.cpp : implementation file
//

#include "stdafx.h"
#include "DialogChildBase.h"
#include "ResUtil.h" 

// CDialogChildBase dialog
CDialogChildBase::CDialogChildBase(UINT nIDTemplate, UINT nBkID, CWnd* pParent /*=NULL*/)
	: CDialogExt( nIDTemplate, pParent)
{
	m_nBKResourceID = nBkID;
}

CDialogChildBase::~CDialogChildBase()
{
}

void CDialogChildBase::DoDataExchange(CDataExchange* pDX)
{
	CDialogExt::DoDataExchange(pDX);
}

void CDialogChildBase::SetBackground(int nId)
{
	m_nBKResourceID = nId;

	CRect rect, Mrect;
	GetParent()->GetClientRect( &Mrect );
	GetClientRect(&rect);

	CClientDC DC(this);
	CBitmap bmp;
	bmp.CreateCompatibleBitmap(&DC, Mrect.Width(), Mrect.Height());

	m_dcBackground.CreateCompatibleDC(&DC);	
	m_dcBackground.SelectObject(&bmp);

	DrawPngResToDC(&m_dcBackground, m_nBKResourceID);
	ReleaseDC(&DC);
}

BEGIN_MESSAGE_MAP(CDialogChildBase, CDialogExt)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

BOOL CDialogChildBase::OnInitDialog()
{
	CDialogExt::OnInitDialog();

	// TODO:  Add extra initialization here
	OnInitCommonControls();
	OnInitChildControls();

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

bool CDialogChildBase::OnInitCommonControls()
{
	SetBackground(m_nBKResourceID);
	return true;
}

BOOL CDialogChildBase::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	if(m_nBKResourceID > 0) {
		CRect rect;
		GetClientRect(&rect);
		pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &m_dcBackground, 0, 0, SRCCOPY);
	}
	return TRUE;
	//return CDialogExt::OnEraseBkgnd(pDC);
}

BOOL CDialogChildBase::PreTranslateMessage(MSG* pMsg)
{
	if(pMsg->message == WM_SYSKEYDOWN)
		return TRUE;

	return CDialogExt::PreTranslateMessage(pMsg);
}